package cn.itcast.nems.journal.converter;

import cn.itcast.nems.journal.dto.JournalChangeDateLineCreate;
import cn.itcast.nems.journal.dto.JournalClazzStartDateChangedDTO;
import cn.itcast.nems.journal.enumeration.JournalStateEnum;
import cn.itcast.nems.studentrecord.dao.entity.JournalChangeDate;
import cn.itcast.nems.studentrecord.dao.entity.JournalChangeDateLine;
import cn.itcast.nems.studentrecord.dto.StudentRecordStudentDTO;
import org.springframework.beans.BeanUtils;

/**
 * author liyong
 * create: 2024-01-11 17:34:31
 **/
public class JournalChangeDateConverter {
    public static JournalChangeDate convert(JournalClazzStartDateChangedDTO changedDTO) {
        JournalChangeDate result = new JournalChangeDate();
        result.setClazzId(changedDTO.getClazzId());
        result.setBeforeStartDate(changedDTO.getOldDate());
        result.setAfterStartDate(changedDTO.getNewDate());
        result.setCreatedName(changedDTO.getOperatorName());
        result.setState(JournalStateEnum.FINISHED.name());
        result.setChangeDatetime(changedDTO.getChangeDateTime());
        result.setRemark("");
        return result;
    }

    public static JournalChangeDateLineCreate convert(StudentRecordStudentDTO student, JournalChangeDate journal) {
        JournalChangeDateLineCreate result = new JournalChangeDateLineCreate();
        result.setJournalChangeDateId(journal.getId());
        result.setStudentRecordId(student.getStudentRecordId());
        result.setStudentId(student.getStudentId());
        result.setStudentNumber(student.getStudentNumber());
        result.setStudentName(student.getStudentName());
        result.setBeforeInDate(student.getInDate().toLocalDate());
        result.setAfterInDate(journal.getAfterStartDate());
        result.setCreatedName(journal.getCreatedName());
        result.setState(JournalStateEnum.FINISHED.name());
        return result;
    }

    public static JournalChangeDateLine convert(JournalChangeDateLineCreate cmd) {
        JournalChangeDateLine line = new JournalChangeDateLine();
        BeanUtils.copyProperties(cmd, line);
        return line;
    }
}
